/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "Creator.h"
#include "Renderer.h"
#include <logs/Log.h>
#include <vector>

namespace liba
{
namespace lib2d
{
namespace hard
{
namespace soft
{

static std::vector< Renderer * > * renderers = 0;

Creator::Creator()
{
	if( renderers )
		throw Gluck(__FUNCTION__, "Renderers already exists");

	logs::log() << __FUNCTION__ << "Creating Renderers\n";
	renderers = new std::vector< Renderer * >();

	Renderer * rend = new Renderer();
	renderers->push_back( rend );
	hard::Manager::add_hardware( rend );
}

Creator::~Creator()
{
	while( !renderers->empty() )
	{
		Manager::remove_hardware( renderers->back() );
		delete renderers->back();
		renderers->pop_back();
	}

	logs::log() << __FUNCTION__ << "Deleting renderers\n";
	delete renderers; renderers = 0;
}

} // namespace soft
} // namespace hard
} // namespace lib2d
} // namespace liba

